package com.xiaoxi.exam.service;

import com.xiaoxi.exam.consts.Const;
import com.xiaoxi.exam.model.PreOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//@Component
public class InitService {

    @Autowired
    private OrderService orderService;
    @Autowired
    private BookService bookService;

    @PostConstruct
    public void init() {
        Const.NEED_BOOK_ORDER.addAll(orderService.getNeedBookOrder());
        while (true) {
            try {
                PreOrder order = Const.NEED_BOOK_ORDER.take();
                bookService.startBook(order);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
